%%%-------------------------------------------------------------------
%% @doc metronome top level supervisor.
%% @end
%%%-------------------------------------------------------------------

-module(metronome_sup).

-behaviour(supervisor).

-export([start_link/0]).

-export([init/1]).

-define(SERVER, ?MODULE).

start_link() ->
    supervisor:start_link({local, ?SERVER}, ?MODULE, []).

%% sup_flags() = #{strategy => strategy(),         % optional
%%                 intensity => non_neg_integer(), % optional
%%                 period => pos_integer()}        % optional
%% child_spec() = #{id => child_id(),       % mandatory
%%                  start => mfargs(),      % mandatory
%%                  restart => restart(),   % optional
%%                  shutdown => shutdown(), % optional
%%                  type => worker(),       % optional
%%                  modules => modules()}   % optional
init([]) ->
    Config          = application:get_all_env(metronome),
    BeatTimer       = proplists:get_value(beat_timer, Config, 333),

    SupFlags = 
        #{ strategy => one_for_all
         , intensity=> 0
         , period   => 1
         },

    Timer = 
        #{ id       => metronome_beat
         , start    => {metronome_beat, start_link, [BeatTimer]}
         , restart  => permanent
         , shutdown => 1000
         , type     => worker
         , modules  => [metronome_beat]
         },

    Subscribe = 
        #{ id       => metronome_subscribe
         , start    => {metronome_subscribe, start_link, []}
         , restart  => permanent
         , shutdown => 1000
         , type     => worker
         , modules  => [metronome_subscribe]
         },

    ChildSpecs = [Timer, Subscribe],
    {ok, {SupFlags, ChildSpecs}}.

%% internal functions

